<template>
	<view class="page ">
		<view class="cu-custom bg-white  fixed" :style="[{ height: CustomBar+82 + 'px' }]">
			<view class="cu-bar bg-top " :style="[{ height: CustomBar + 'px', paddingTop: StatusBar + 'px' }]">
				<view class=" width-120 "></view>
				<view class="text-lg">订单管理</view>
				<view class="   width-120"> </view>
			</view>
			<view class="">
				<view class="flex align-center justify-between bg-nav margin-lr-48 radius-100">
					<view class="text-df padding-tb-16 padding-lr-48 radius-100"
						:class="selectIndex==0?'text-white bg-theme1':'text-999'" @tap='selectNav(0)'>订单列表 </view>
					<view class="text-df padding-lr-48 padding-tb-16 radius-100"
						:class="selectIndex==1?'text-white bg-theme1':'text-999'" @tap='selectNav(1)'>拼团订单 </view>
					<view class="text-df padding-lr-48 padding-tb-16 radius-100"
						:class="selectIndex==2?'text-white bg-theme1':'text-999'" @tap='selectNav(2)'>售后订单</view>
				</view>
				<view class=" padding-lr padding-tb-14 margin-lr margin-top-sm bg-f8 flex align-center round">
					<text class="cuIcon-search  margin-right-sm text-999"></text>
					<input confirm-type="search" class=" text-sm w90 " type="text" v-model="keywords" :adjust-position="false"
						placeholder-class="text-999" :hold-keyboard="false" placeholder="请输入订单号" @confirm="searchConfirm" />
					<text v-if="keywords.length != 0" class="cuIcon-close  padding-right-xs" @tap="handleClear"></text>
				</view>
			</view>
		</view>
		<fu-tab :tabs="navList" :selectIndex='selectIndex' :sactive='active1' pageType='order' :sticky="true"
			line-height="8" radius="80" bottom="0" :top="CustomBar+80" node-title="text" @change="tabClick" node-key="state"
			:scrollspy='scrollspy' :current="type" current-key="type" :line-color="themeColor" :active-color="themeColor"
			@openPop='openPop'>
		</fu-tab>
		<!-- 订单状态栏Tab-结束 -->
		<!-- 订单列表-开始 -->
		<view class="list margin-lr-sm margin-top-sm padding-bottom-20 relative" :style="{top :CustomBar+80+'px'}">
			<block v-for="(item, index) in listData" :key="index">
				<order-item :item="item" :selectIndex='selectIndex' :index="index" @showCancelReason="showCancelReason"
					@showOrderPop='showOrderPop' @refunceApply='refunceApply'></order-item>
			</block>
		</view>
		<!-- 订单列表-结束 -->
		<view class="relative" :style="{top :CustomBar+80+'px'}">
			<fu-empty :paging-list-loaded-all="pagingListLoadedAll" :paging-list-no-list-data="pagingListNoListData"
				:list-data-length="listDataLength" :isLoadInit='isLoadInit'></fu-empty>
		</view>
		<view class="back-success-wrap" v-if="refundPop">
			<view class="mask" @click="refundPop = false">
			</view>
			<view class="back-content flex flex-direction justify-between align-center">
				<view class="back-content-info bg-white flex flex-direction justify-between align-center">
					<view class="text-bold text-333 ">拒绝申请售后的原因</view>
					<view class="bg-f8 padding-sm width-480 margin-lr radius-16 height-250">
						<textarea type="text" v-model="refundReason" placeholder-class="text-eee"
							class="text-333 w100 height-200 text-df" maxlength="50" placeholder="请输入拒绝申请售后的原因"></textarea>
					</view>
					<view class="text-theme text-df text-333 text-center padding-top solid-top w100" @tap='confirmRefund'> 确认
					</view>
				</view>
				<view class="cuIcon-roundclose text-white text-xxl  text-62" @click="refundPop = false">
				</view>
			</view>
		</view>
		<!-- 蓝牙列表弹框 -->
		<fu-popup v-model="listPopup" mode="center">

			<view class="list-popup">
				<view class="padding-bottom text-center fu-fs32 text-bold"> 蓝牙设备 </view>
				<scroll-view scroll-y="true" style="height: 600rpx; ">
					<view @click="linkDevice(item, index)" class="padding-tb solid-bottom" v-for="(item, index) in devices"
						:key="index">
						<view class="deviceId block">BT:{{ item.deviceId }}</view>
						<view class="margin-top-sm block">产品型号:{{ item.name }}</view>
					</view>
					<view class="text-center" v-if='devices.length==0'>
						没有找到蓝牙设备
					</view>
				</scroll-view>
			</view>
		</fu-popup>
		<fu-popup v-model="showOrderPopup" mode="center" border-radius="24" :z-index="998">
			<view class="cancel-order-pop bg-white width-682 " style="height: 78vh;">
				<view class="flex justify-between padding align-center">
					<view class="text-999  text-df"></view>
					<view class=" text-333 text-lg text-bold">打印订单码</view>
					<view class=" text-999 text-df" @click="showOrderPopup = false">
						<text class="cuIcon-roundclosefill text-lg"></text>
					</view>
				</view>
				<view class="pop-count ">
					<scroll-view scroll-y="true" style="height: 560rpx; ">
						<view class="pop-count-list">
							<view class="item flex align-center justify-between" v-for="(item, index) in orderCodeList" :key="index">
								<view class="">
									<view class="text-bold text-333">{{ item.package_name }}</view>
									<view class="margin-top-sm text-df">订单码：{{ item.bar_code }}</view>
								</view>
								<view class="flex align-center flex-shrink">
									<view class="bg-f8 radius-100 line-f8 padding-tb-xs text-333 padding-lr margin-right-xs"
										@tap='delItem(item,index)'>删除
									</view>
									<view class="bg-themeOp line-theme radius-100 padding-tb-xs text-333 padding-lr"
										@tap='putItem(item,index)'>打印
									</view>
								</view>
							</view>
						</view>
					</scroll-view>
					<view class="flex margin-lr align-center justify-between bg-themeOp radius-10 padding-tb-sm padding-lr">
						<uni-number-box :value="pageNum" :min="1" :max="max" @change="setnumber" :step="1">
						</uni-number-box>
						<view class="bg-theme1 text-white radius-100 padding-tb-xs  padding-lr-40" @tap='addOrder'>添加
						</view>
					</view>
					<!-- <view class="flex align-center  margin-top margin-lr">
						<view class="  radius-100 padding-tb-xs  padding-lr-40" @tap='chooseOne(1)'
							:class="chooseIndex==1?'bg-theme1 text-white':'bg-f8 text-333'">整件</view>
						<view class=" radius-100 padding-tb-xs  padding-lr-40 margin-left" @tap='chooseOne(2)'
							:class="chooseIndex==2?'bg-theme1 text-white':'bg-f8 text-333'">散件</view>
					</view> -->
					<view class="flex align-center justify-between text-df  margin-top-50 margin-lr">
						<view class="line-theme radius-100 padding-tb-18 bg-themeOp width-280 text-center " @tap='putAll'>打印全部
						</view>
						<view class="bg-theme1 text-white  radius-100 padding-tb-18  width-280 text-center" @tap='confirmPut'>确认完成
						</view>
					</view>
				</view>
			</view>
		</fu-popup>
		<fu-popup v-model="showDrawer" mode="right" :safe-area-inset-bottom="true" :border-radius="0" width='75%'>
			<view class="container " :style="[{paddingTop: CustomBar+'px'}]">
				<scroll-view class="pop-content" scroll-y>
					<view class="title" style="font-size: 32rpx;margin-bottom: 30rpx;"> 筛选</view>
					<view class="" v-if="selectIndex!=1">
						<view class="title margin-top-sm">订单号 </view>
						<view class="title margin-top-sm text-df bg-f8 padding-lr-sm padding-tb-16 radius-6">
							<input placeholder="请输入订单号" type="text" v-model='keywords' class="text-sm" placeholder-class="text-sm"
								maxlength="20">
						</view>
					</view>
					<view class="title flex align-center margin-top justify-between">
						<view class="">下单时间 </view>
						<view class="flex text-sm text-999 align-center">
							<view class="bg-f8 padding-lr-sm padding-tb-4 radius-6 margin-right-sm" @tap="chooseTime('','date',0)">近日
							</view>
							<view class="bg-f8 padding-lr-sm padding-tb-4 radius-6" @tap="chooseTime('','date',1)">近30天
							</view>
						</view>
					</view>
					<view class='margin-top flex align-center'>
						<view class="bg-f8 radius-10 text-sm text-center width-230 padding-tb-xs"
							@tap="chooseTime('start','date',2)">
							<text>{{start_time||'请选择'}}</text>
							<!-- <input placeholder="请选择" type="number" class="text-333" v-model="start_time"
								placeholder-class="text-sm" disabled="true"> -->
						</view>
						<view class="margin-lr-sm text-999">—</view>
						<view class="bg-f8 radius-10 text-sm text-center width-230 padding-tb-xs" @tap="chooseTime('end','date',2)">
							<text>{{end_time||'请选择'}}</text>
							<!-- <input placeholder="请选择" type="number" class="text-333" v-model='end_time'
								placeholder-class="text-sm" disabled="true"> -->
						</view>
					</view>
					<view class="brand title margin-top">
						{{selectIndex==2?'售后状态':'订单状态'}}
					</view>
					<view class=' margin-top-sm flex-wrap  flex align-center '>
						<view v-for='item in navList'
							class="bg-f8 box-item radius-10  margin-bottom-sm  margin-right-sm padding-tb-14 width-160 text-center text-sm text-333 radius"
							:class="[item.selected ? 'active2 ':'line-f8 ' ]" @click='Choice1(item)'>{{item.text}}
						</view>
					</view>
					<view class="margin-top" v-if="selectIndex==0">
						<view class="brand title ">订单类型</view>
						<view class='margin-top flex-wrap  flex align-center'>
							<view v-for='item in typeList'
								class="bg-f8 radius-10 box-item margin-bottom-sm margin-right-sm  padding-tb-14 width-160 text-center text-sm text-333 radius"
								:class="[item.selected ? 'active2 ':'line-f8 ' ]" @click='Choice2(item)'>{{item.name}}
							</view>
						</view>
					</view>
					<view class="margin-top" v-if="selectIndex==2">
						<view class="brand title ">售后方式 </view>
						<view class='margin-top flex-wrap  flex align-center'>
							<view v-for='item in refundList'
								class="bg-f8 radius-10 box-item margin-bottom-sm margin-right-sm  padding-tb-14 width-160 text-center text-sm text-333 radius"
								:class="[item.selected ? 'active2 ':'line-f8 ' ]" @click='Choice3(item)'>{{item.name}}
							</view>
						</view>
					</view>
				</scroll-view>
				<view class="action-box pop-btn">
					<view class="action reset" @tap.stop="resetPop">{{i18n['重置']}}</view>
					<view class="action confirm" @tap.stop="confirmPop">{{i18n['确定']}}</view>
				</view>
			</view>
		</fu-popup>
		<!-- 取消订单弹出层-开始 -->
		<fu-popup v-model="showPopup" mode="bottom" border-radius="24">
			<view class="cancel-order-pop">
				<view class="flex justify-between align-center" style="padding:0 32rpx;">
					<view class="text-999 text-weight-400 text-df" @click="showPopup = false">{{ i18n['取消'] }}</view>
					<view class="pop-title">{{ i18n['取消订单'] }}</view>
					<view class="text-theme text-weight-400 text-df" @click="cancelOrder()">{{ i18n['确定'] }}</view>
				</view>
				<view class="pop-count">
					<view class="tips text-sm">{{ i18n['请选择取消订单原因'] }}</view>
					<scroll-view scroll-y="true" style="max-height: 400rpx; min-height: 200rpx">
						<view class="pop-count-list">
							<view @click="onChangeReson(item, index)" class="item flex align-center justify-between"
								v-for="(item, index) in reasonList" :key="index">
								<view class="item-label">{{ item.reason }}</view>
								<image v-if="index == cancelObj.current" class="item-img" src="../../static/icon-select-2.png"
									mode="aspectFit"></image>
								<image v-else src="../../static/icon-select-1.png" mode="aspectFit" class="item-img"></image>
							</view>
						</view>
					</scroll-view>
				</view>
			</view>
		</fu-popup>
		<!-- 取消订单弹出层-结束 -->
		<w-picker :visible.sync="timeVisible" mode="date" fields="day" :disabled-after="true"
			@confirm="onConfirm($event, 'date')" ref="date">选择日期</w-picker>
		<!-- 断网监测 -->
		<fu-notwork></fu-notwork>
	</view>
</template>

<script>
	import orderItem from '../../components/order-item/order-item.vue';
	import afterorderItem from '../../components/order-item/afterorder_item.vue';
	import pagingList from '@/common/mixin/paging_list.js' //引入混合开发
	/** 订单状态列表
	 * all 全部订单
	 * unpay 待付款订单
	 * unship 待发货订单
	 * unreceive 待收货订单
	 * finish 待评价订单
	 * refund 退款/售后
	 * */
	//非入仓商家 用户下单-》供应商接单-》备货-》分理处取货-》物流扫码收货-》核验装车-》送货-》代理收货（如果用户没有代码这一步跳过）-》用户收货
	// 入仓商家 用户下单-》贴码员贴码-》分理处取货-》物流扫码收货-》核验装车-》送货-》代理收货（如果用户没有代码这一步跳过）-》用户收货
	export default {
		mixins: [pagingList],
		components: {
			orderItem,
			afterorderItem
		},
		data() {
			return {
				imgWechatUrl: this.imgWechatUrl,
				scrollspy: false,
				timeVisible: false,
				tabCurrentIndex: 0, // tab切换选中状态下标
				type: 'all', // 当前选中的状态key
				refundList: [{
					name: '全部',
					selected: true,
					id: 0
				}, {
					name: '仅退款',
					selected: false,
					id: 1
				}, {
					name: '退款退货',
					selected: false,
					id: 2
				}],
				typeList: [{
					name: '全部',
					selected: true,
					id: 0
				}, {
					name: '秒杀',
					selected: false,
					id: 6
				}, {
					name: '预售',
					selected: false,
					id: 7
				}, {
					name: '拼团',
					selected: false,
					id: 5
				}],
				navList: [{
						state: 0,
						text: global.i18n['全部'],
						type: 'all',
						selected: true
					},
					{
						state: 1,
						text: '待支付',
						type: 'unpay',
						selected: false
					},
					{
						state: 2,
						text: '待接单',
						type: 'taking',
						selected: false
					},
					{
						state: 3,
						text: '备货中',
						type: 'ready',
						selected: false
					},
					{
						state: 4,
						text: '待送货',
						type: 'send',
						selected: false
					},
					{
						state: 5,
						text: '配送中',
						type: 'distribution',
						selected: false
					}, {
						state: 6,
						text: '待收货',
						type: 'receive',
						selected: false
					}, {
						state: 7,
						text: '待评价',
						type: 'evaluate',
						selected: false
					}
				], // 订单状态切换列表
				minixPagingListsApi: '/v1/63dccd5580b60', //明细请求地址
				pageingListApiMethod: "post", //请求方法
				allowOnloadGetList: false, // 是否允许页面onload生命周期进入后立马执行getlist
				showPopup: false, // 控制取消订单弹出层是否显示
				selectIndex: '0', //分类索引
				reasonList: [], //取消原因列表
				max: 1000, //
				pageNum: 1, //
				active1: 0, //选择的订单状态
				order_aid: '', //单个订单id
				orderItem: '', //单个订单信息
				start_time: '', // 时间
				end_time: '', // 时间
				after_sale: 0, // 退款类型 0 全  1仅退款 2退货退款
				order_type: 0, // 0：全部 5：拼团 6：秒杀 7：预售 9：折扣
				orderSnIpt: '', //订单号
				chooseIndex: 1, //整件  散件
				showOrderPopup: false, //订单码
				keywords: '', //
				showDrawer: false, // 侧边遮罩
				refundPop: false, //拒绝售后弹框
				orderCodeList: [], //订单码列表
				refundReason: '', //拒绝售后原因
				cancelObj: {
					//订单取消对象
					current: -1, //当前原因索引
					id: '', //档原因id
					orderSn: null, //要取消的订单号
					index: null, //要取消的订单在列表中的索引
					orderItem: {} //当前订单对象
				},
				listPopup: false, //是否显示蓝牙列表
				isLoading:false,//放连点
			};
		},
		computed: {
			themeColor() {
				return this.$store.state.themeColor;
			},
			//搜索到的蓝牙列表
			devices: {
				get() {
					return this.$store.state.devices
				},
				set(val) {
					this.$store.commit("setDevices", val);
				}
			},
			//是否有链接的设备
			isConDevice: {
				get() {
					return this.$store.state.isConDevice
				},
				set(val) {
					this.$store.commit("setIsConDevice", val);
				}
			}
		},
		onLoad(options) {

			uni.$on('onDevicesRes', res => {
				console.log('onDevicesRes', res.data);
				this.devices = res.data;
			});
			if (!global.$printer.deviceId) {
				global.$printer.init();
			} else {
				global.$printer.getBluetoothDevices();
			}

			this.getReasonList();
			// 监听页面更新
			uni.$on('onPageUpdata', data => {
				this.pagingListToggle();
			});
			uni.$on('updateAfterOrder', data => {
				this.pagingListToggle();
			});
			uni.$on('PRINT_SUCC', data => {
				this.$message.info('打印成功')
			})

		},
		onShow() {
			if (global.userInfo && global.userInfo.run_type == 1) {
				this.setTabBarItem1();
			} else { //非入仓
				this.setTabBarItem();
			}
			if (global.token) {
				this.$store.dispatch('getCartList');
			}
			if (uni.getStorageSync('orderType') != 'refund') {
				this.selectIndex=0
				this.navList= [{
							state: 0,
							text: global.i18n['全部'],
							type: 'all',
							selected: true
						},
						{
							state: 1,
							text: '待支付',
							type: 'unpay',
							selected: false
						},
						{
							state: 2,
							text: '待接单',
							type: 'taking',
							selected: false
						},
						{
							state: 3,
							text: '备货中',
							type: 'ready',
							selected: false
						},
						{
							state: 4,
							text: '待送货',
							type: 'send',
							selected: false
						},
						{
							state: 5,
							text: '配送中',
							type: 'distribution',
							selected: false
						}, {
							state: 6,
							text: '待收货',
							type: 'receive',
							selected: false
						}, {
							state: 7,
							text: '待评价',
							type: 'evaluate',
							selected: false
						}]
				this.type = uni.getStorageSync('orderType')||'all';
				this.active1 = this.navList.findIndex(item => item.type == this.type)
				console.log(this.type,this.active1,'type,active1');
			} else {
				this.selectIndex = 2
				this.active1 = 0
			}
			this.allowOnloadGetList = true
			this.pagingListToggle();
		},
		onUnload() {
			console.log('onUnload');
			// 移除页面更新监听
			uni.$off('onPageUpdata');
			uni.$off('updateAfterOrder');
			clearInterval(this.timer);
			this.timer = null;
			uni.$off('onDevicesRes');
			uni.$off('PRINT_SUCC');
		},
		onHide() {
			console.log('onHide');
			// this.type='all'
			// this.active1=0
			// this.selectIndex=0
		},
		methods: {
			// 拒绝申请
			refunceApply(e) {
				this.refundPop = true
				this.rfid = e.id
			},
			confirmRefund() {
				if (!this.refundReason) {
					return this.$message.info('请输入拒绝原因')
				}
				this.$api.post('/v1/63e4ab6dafd48', {
					reject_reason: this.refundReason,
					rfid: this.rfid
				}).then(result => {
					if (result.data.code == 1) {
						this.$message.info('已拒绝');
						this.pagingListToggle();
						this.refundReason = ''
						this.showOrderPopup = false
					} else {
						this.$message.info(data.msg);
					}
				}).catch(err => {
					this.$message.info('服务器错误，请稍后重试');
				});
			},
			selectNav(e) {
				this.selectIndex = e
				this.type='all'
				
				if (this.selectIndex == 0) {
					this.scrollspy = false
					this.navList = [{
							state: 0,
							text: global.i18n['全部'],
							type: 'all',
							selected: true
						},
						{
							state: 1,
							text: '待支付',
							type: 'unpay',
							selected: false
						},
						{
							state: 2,
							text: '待接单',
							type: 'taking',
							selected: false
						},
						{
							state: 3,
							text: '备货中',
							type: 'ready',
							selected: false
						},
						{
							state: 4,
							text: '待送货',
							type: 'send',
							selected: false
						},
						{
							state: 5,
							text: '配送中',
							type: 'distribution',
							selected: false
						}, {
							state: 6,
							text: '待收货',
							type: 'receive',
							selected: false
						}, {
							state: 7,
							text: '待评价',
							type: 'evaluate',
							selected: false
						}
					]
				} else if (this.selectIndex == 1) {
					this.scrollspy = false
					this.navList = [{
						state: 0,
						text: global.i18n['全部'],
						type: 'all',
						selected: true
					}, {
						state: 0,
						text: '拼团中',
						type: 'ongoing',
						selected: false
					}, {
						state: 0,
						text: '已成团',
						type: 'successfully',
						selected: false
					}, {
						state: 0,
						text: '拼团失败',
						type: 'fail',
						selected: false
					}]
				} else {
					this.scrollspy = false
					this.navList = [{
						state: 0,
						text: global.i18n['全部'],
						type: 'all',
						selected: true
					}, {
						state: 0,
						text: '申请中',
						type: 'apply',
						selected: false
					}, {
						state: 0,
						text: '待取货',
						type: 'pickup',
						selected: false
					}, {
						state: 0,
						text: '待收货',
						type: 'wait_revice',
						selected: false
					}, {
						state: 0,
						text: '已完成',
						type: 'have_refund',
						selected: false
					}, {
						state: 0,
						text: '已拒绝',
						type: 'have_refused',
						selected: false
					}, {
						state: 0,
						text: '已取消',
						type: 'cancel',
						selected: false
					}]
				}
				this.keywords = ''
				this.pagingListToggle();
			},
			setnumber(e) {
				this.pageNum = e
			},
			searchConfirm() {
				this.pagingListToggle();
			},
			// 清除关键字
			handleClear() {
				this.keywords = '';
				uni.hideKeyboard();
				this.pagingListToggle();
			},
			/**
			 * @description  设置要请求的参数
			 * 在混入开发时，调用该方法和混入的请求参数合并在一起
			 */
			pagingListPostData() {
				let data = {}
				if (this.selectIndex == 2) { //售后订单
					this.minixPagingListsApi = '/v1/63e4a470271c8';
					// apply:申请中;deal：已处理;pickup:待取货;have_refund:已退款;have_refused:已拒绝  wait_revice：待收货；cancel：已取消
					data = {
						after_sale: this.after_sale, //0全部 1仅退款 2退货退款
					}
				} else if (this.selectIndex == 1) { //拼团订单  all:全部 ongoing进行中 successfully已成团 fail 拼团失败
					this.minixPagingListsApi = '/v1/63e20e3ef15b8';

				} else { //订单列表
					//  unpay：待支付   taking：待接单  ready：备货中  send：待送货   distribution：配送中    receive：待收货  evaluate：待评价  finish：已完成
					this.minixPagingListsApi = '/v1/63dccd5580b60';
					data.order_type = this.order_type //不传或0：全部 5：拼团 6：秒杀 7：预售 9：折扣

				}
				data.type = this.type //
				data.keywords = this.keywords
				data.start_time = this.start_time
				data.end_time = this.end_time
				return data
			},
			showOrderPop(val) {
				console.log(val, '==========');
				this.showOrderPopup = true
				if (val) {
					this.orderItem = val.item
					this.order_aid = val.item.aid
				}

				this.$api.post('/v1/63e1f69b6e410', {
					order_aid: this.order_aid
				}).then(result => {
					if (result.data.code == 1) {
						this.orderCodeList = result.data.data

					} else {
						this.$message.info(data.msg);
					}
				}).catch(err => {
					this.$message.info('服务器错误，请稍后重试');
				});
			},
			chooseOne(e) {
				this.chooseIndex = e
			},
			chooseTime(type, ref, e) {
				var today = new Date(); // 获取当前日期

				var yesterday = new Date(today.getTime() - 24 * 3600 * 1000); // 计算昨天日期
				var year = yesterday.getFullYear(); // 获取年份
				var month = yesterday.getMonth() + 1; // 获取月份，注意月份从0开始计数，需要加1
				var day = yesterday.getDate(); // 获取日期
				var before30days = new Date(today.getTime() - 30 * 24 * 3600 * 1000); // 计算前30天日期
				var year1 = before30days.getFullYear(); // 获取年份
				var month1 = before30days.getMonth() + 1; // 获取月份，注意月份从0开始计数，需要加1
				var day1 = before30days.getDate(); // 获取日期
				var year2 = new Date(today.getTime()).getFullYear(); // 获取年份
				var month2 = new Date(today.getTime()).getMonth() + 1; // 获取月份，注意月份从0开始计数，需要加1
				var day2 = new Date(today.getTime()).getDate(); // 获取日期

				if (month < 10) {
					month = '0' + month;
				}
				if (day < 10) {
					day = '0' + day;
				}
				if (month1 < 10) {
					month1 = '0' + month1;
				}
				if (day1 < 10) {
					day1 = '0' + day1;
				}
				if (month2 < 10) {
					month2 = '0' + month2;
				}
				if (day2 < 10) {
					day2 = '0' + day2;
				}
				if (e == 2) {
					this.timeType = type
					this.$refs[ref].show();
				} else if (e == 0) { //近日
					this.start_time = year + '-' + month + '-' + day
					this.end_time = year2 + '-' + month2 + '-' + day2
				} else { //近30天
					this.start_time = year1 + '-' + month1 + '-' + day1
					this.end_time = year2 + '-' + month2 + '-' + day2
				}
				this.$forceUpdate()
				console.log(this.start_time, this.end_time, '===========');

			},
			// 重置筛选条件
			resetPop() {
				this.start_time = ''
				this.end_time = ''
				this.keywords = ''
				this.order_type = 0
				this.after_sale = 0
				this.type = 'all'
				this.navList.map(item => {
					item.selected = false
				})
				this.navList[0].selected = true
				this.refundList.map(item => {
					item.selected = false
				})
				this.refundList[0].selected = true
				this.typeList.map(item => {
					item.selected = false
				})
				this.typeList[0].selected = true
				this.confirmPop()
			},
			onConfirm(result, type) {
				console.log(result, 'result');
				if (this.timeType == 'start') {
					this.start_time = result.value;
				} else if (this.timeType == 'end') {
					this.end_time = result.value;
				}
				console.log(this.start_time, this.end_time, 'this.minVal');

				this.$forceUpdate()
			},
			// 选择订单状态
			Choice1(item) {
				this.navList.map(item => {
					item.selected = false
				})
				item.selected = true
				this.type = item.type
			},
			// 选择订单类型
			Choice2(item) {
				this.typeList.map(item => {
					item.selected = false
				})
				item.selected = true
				this.order_type = item.id
			},
			Choice3(item) {
				this.refundList.map(item => {
					item.selected = false
				})
				item.selected = true
				this.after_sale = item.id
			},
			// 提交确认高级筛选
			confirmPop(val) {
				if (this.start_time && this.end_time) {
					if (Number(this.start_time) > Number(this.end_time)) {
						[this.start_time, this.end_time] = [this.end_time, this.start_time]
					}
				}
				this.active1 = this.navList.findIndex(item => item.type == this.type)
				this.pagingListToggle();
				this.showDrawer = false;

			},
			// 删除订单码
			delItem(item, index) {
				this.$util.showModal({
					title: '确定删除当前内容',
					content: this.i18n['删除后不可恢复'],
					success: res => {
						if (res.confirm) {
							this.$api.post('/v1/63e1f16ab29d0', {
								package_id: item.id
							}).then(result => {
								if (result.data.code == 1) {
									this.$message.info(this.i18n['删除成功']);
									this.orderCodeList.splice(index, 1)
								} else {
									this.$message.info(data.msg);
								}
							}).catch(err => {
								this.$message.info('服务器错误，请稍后重试');
							});
						}
					}
				});
			},
			/**
			 * @description 链接蓝牙设备
			 * @param {Object} item
			 * @param {Object} index
			 */
			linkDevice(item, index) {
				this.listPopup = false;
				global.$printer.linkDevice(item, index);
			},
			// 打印订单码
			putItem(item, index) {
				let data = [];
				data.push({
					packageName: item.package_name,
					packageAll: this.orderCodeList && this.orderCodeList.length,
					packageIndex: index + 1,
					userName: item.print_info.user_nickname,
					sendNum: item.print_info.send_number,
					createTime: item.print_info.create_time,
					orderSn: item.order_sn,
					barCode: item.bar_code,
					qRCode: 2,
					storeName:uni.getStorageSync('storeInfo').shopName,
					address:item.print_info.area,
					orderCode:item.print_info.order_code,
					addressDesc:'',
				})
				console.log(global.$printer.deviceId, this.devices, '===========');
				if (global.$printer.deviceId && this.devices && this.devices.length > 0) {
					this.devices.forEach(e => {
						if (global.$printer.deviceId == e.deviceId) {
							this.isConDevice = '1';
						}
					})
					console.log(this.isConDevice, 'this.isConDevice');
					if (this.isConDevice == '0') {
						global.$printer.init();
					} else {
						global.$printer.getServicesSuccess(global.$printer.deviceId);
					}
				}
				if (this.isConDevice == '0') {
					// this.printPopupshow = false;
					this.$message.info('请先链接蓝牙设备');
					this.listPopup = true;
					return false;
				}
				setTimeout(() => {
					global.$printer.printFaceSheet(data[0]);
				}, 1000)
			},
			// 确认完成
			confirmPut() {
				if (this.orderCodeList.length == 0) {
					return this.$message.info('请先添加订单码并打印')
				}
				this.$api.post('/v1/63e1fc4ea4740', {
					order_aid: this.orderItem.aid,
				}).then(result => {
					if (result.data.code == 1) {
						this.showOrderPop()
						this.$message.info('备货成功');
						this.pagingListToggle()
						this.showOrderPopup = false

					} else {
						this.$message.info(data.msg);
					}
				}).catch(err => {
					this.$message.info('服务器错误，请稍后重试');
				});
			},
			// 打印全部
			putAll() {
				let data = [];
				if (this.orderCodeList.length == 0) {
					return this.$message.info('请先添加订单码')
				}

				for (let i = 0; i < this.orderCodeList.length; i++) {
					data.push({
						packageName: this.orderCodeList[i].package_name,
						packageAll: this.orderCodeList && this.orderCodeList.length,
						packageIndex: i + 1,
						userName: this.orderCodeList[i].print_info.user_nickname,
						sendNum: this.orderCodeList[i].print_info.send_number,
						createTime: this.orderCodeList[i].print_info.create_time,
						orderSn: this.orderCodeList[i].order_sn,
						barCode: this.orderCodeList[i].bar_code,
						qRCode: 2,
						storeName:uni.getStorageSync('storeInfo').shopName,
						address:this.orderCodeList[i].print_info.area,
					})
				}
				// console.log(global.$printer.deviceId, this.devices, '===========');
				if (global.$printer.deviceId && this.devices && this.devices.length > 0) {
					this.devices.forEach(e => {
						if (global.$printer.deviceId == e.deviceId) {
							this.isConDevice = '1';
						}
					})
					console.log(this.isConDevice, 'this.isConDevice');
					if (this.isConDevice == '0') {
						global.$printer.init();
					} else {
						global.$printer.getServicesSuccess(global.$printer.deviceId);
					}
				}
				if (this.isConDevice == '0') {
					console.log(this.devices, 'this.devices');
					// this.printPopupshow = false;
					this.$message.info('请先链接蓝牙设备');
					this.listPopup = true;
					return false;
				}
				for (let i = 0; i < this.orderCodeList.length; i++) {
					setTimeout(() => {
						global.$printer.printFaceSheet(data[i]);
					}, i * 4000 + 1000)
				}
			},
			// 添加  	
			addOrder() {
				if (this.isLoading) {
					return this.$message.info('您操作太快了')
				}
				this.isLoading = true
				setTimeout(() => {
					this.isLoading = false
				}, 2000)
				this.$api.post('/v1/63e1c41466ee0', {
					order_aid: this.order_aid,
					type: this.chooseIndex, //1整件 2散件
					num: this.pageNum
				}).then(result => {
					if (result.data.code == 1) {
						this.$message.info('添加成功');
						this.showOrderPop()
					} else {
						this.$message.info(data.msg);
					}
				}).catch(err => {
					this.$message.info('服务器错误，请稍后重试');
				});
			},
			/**
			 * @description 获取取消原因列表
			 */
			getReasonList() {
				this.$api.post(global.apiUrls.getReasonList, {
					type: 2
				}).then(res => {
					let data = res.data;
					if (data.code == 1) {
						this.reasonList = data.data;
					} else {
						this.$message.info(res.data.msg);
					}
				}).catch(err => {
					this.$message.info("服务器错误，请稍后重试");
				});
			},
			openPop() {
				this.showDrawer = true
			},
			// tab切换
			tabClick(e) {
				let index = e.index;
				this.tabCurrentIndex = index;
				this.type = this.navList[index].type;
				console.log(index,this.type, '======');
				uni.setStorageSync('orderType',this.type)
				this.pagingListToggle();
			},
			/**
			 * @description 监听页面更新的回调函数
			 * @param {Object} e = 要更新的配置参数
			 */
			onPageUpdata(e) {
				let index = e.index;
				let item = this.listData[index];
				switch (e.type) {
					case 1: // 取消订单
						if (this.tabCurrentIndex == 0) {
							item.status = -1;
							this.listData.splice(index, 1, item);
						} else {
							this.listData.splice(index, 1);
						}
						break;
					case 2: // 提醒发货
						item.is_remind.info = 1;
						this.listData.splice(index, 1, item);
						break;
					case 3: //确认收货
						if (this.tabCurrentIndex == 0) {
							item.status = 3;
							this.listData.splice(index, 1, item);
						} else {
							this.listData.splice(index, 1);
						}
						break;
					case 4: //删除订单
						this.listData.splice(index, 1);
						break;
					case 5: //评价
						if (this.tabCurrentIndex == 0) {
							item.status = 4;
							this.listData.splice(index, 1, item);
						} else {
							this.listData.splice(index, 1);
						}
						break;
					case 6: // 提交售后
						this.pagingListToggle();
						break;
					case 7: // 删除售后订单
						if (this.tabCurrentIndex == 0) {
							this.pagingListToggle();
						} else {
							this.listData.splice(index, 1);
						}
						break;
					case 8: // 付款成功
						if (this.tabCurrentIndex == 0) {
							item.status = 1;
							this.listData.splice(index, 1, item);
						} else {
							this.listData.splice(index, 1);
						}
						break;
					default:
						break;
				}
			},
			/**
			 * @description 展示取消原因
			 * @param {Object} item = 当前订单项对象
			 * @param {Number} index = 当前订单在列表中的索引
			 */
			showCancelReason(e) {
				this.cancelObj.orderSn = e.item.order_sn;
				this.cancelObj.index = e.index;
				this.cancelObj.orderItem = e.item;
				this.cancelObj.current = -1;
				this.cancelObj.id = '';
				this.showPopup = true;
			},

			/**
			 * @description 取消订单
			 * @param {string} sn = 订单号
			 * */
			cancelOrder() {
				if (!this.cancelObj.id) return this.$message.info(this.i18n['请选择取消原因']);
				this.$api.post(global.apiUrls.postCancelOrder, {
					order_sn: this.cancelObj.orderSn,
					return_id: this.cancelObj.id
				}).then(res => {
					this.$message.info(res.data.msg);
					if (res.data.code == 1) {
						this.showPopup = false;
						this.cancelObj.id = '';
						uni.$emit('onPageUpdata', {
							type: 1, // 1: 取消订单， 2: 提醒发货， 3: 确认订单， 4: 删除订单，
							index: this.cancelObj.index,
						})
					} else {

					}
				}).catch(err => {
					this.$message.info('服务器错误，请稍后重试');
				});
			},

			/**
			 * @description 监听切换取消原因
			 * @param {Object} item = 当前原因项
			 * @param {Number} index = 当前原因在列表中的索引
			 */
			onChangeReson(item, index) {
				if (this.cancelObj.current == index) return false;
				this.cancelObj.current = index;
				this.cancelObj.id = item.id;
			},
			// 取消申请
			cancelAfter(item) {
				let that = this;
				if (that.is_click) return;
				this.$util.showModal({
					title: this.i18n['提示'],
					content: this.i18n['确定取消申请吗？'],
					cancelText: this.i18n['取消'],
					confirmText: this.i18n['确定'],
					success: res => {
						if (res.confirm) {
							that.$api
								.post(global.apiUrls.getGoodsAfterSaleCentel, {
									id: item.id
								})
								.then(res => {
									console.log(res);
									that.$message.info(res.data.msg);
									if (res.data.code == 1) {
										this.$message.info("取消成功");
									}
								})
								.catch(err => {
									console.log('err: ' + JSON.stringify(err));
								});
						}
					}
				});
			},
			// 去售后详情
			toDetail(item) {
				this.$urouter.navigateTo({
					url: '/pages/order/afterorder/afterorder-detail/index',
					params: {
						id: item.id
					}
				})
			},
			/**
			 * @description 判断内容是否显示
			 * @param {String} arr = 要判端数组
			 * @param {String | Number} val = 要判的值
			 */
			isContentShow(arr, val) {
				return arr.includes(val * 1);
			},
		},
	};
</script>

<style lang="scss" scoped>
	.page {
		min-height: calc(100vh - 88rpx);
	}

	.bg-nav {
		background: rgba(#F97F33, 0.1);
	}

	.fixed {
		position: fixed;
		top: 0;
		width: 100%;
		z-index: 100;
	}

	// 取消订单弹出层-开始
	.cancel-order-pop {
		border-radius: 24rpx 24rpx 0 0;

		.pop-title {
			line-height: 114rpx;
			height: 114rpx;
			text-align: center;
			font-size: 36rpx;
			font-weight: bold;
		}

		.pop-count {
			.tips {
				line-height: 90rpx;
				background-color: #f8f8f8;
				padding: 0 24rpx;
				color: #666;
			}

			.pop-count-list {
				padding: 32rpx 24rpx;

				.item {
					padding-bottom: 32rpx;

					.item-img {
						width: 32rpx;
						height: 32rpx;
					}
				}
			}
		}
	}

	// 取消订单弹出层-结束
	.back-success-wrap {
		.mask {
			position: fixed;
			top: 0;
			left: 0;
			right: 0;
			bottom: 0;
			z-index: 99;
			background: rgba(0, 0, 0, 0.3);
		}

		.back-content {
			position: fixed;
			top: 50%;
			left: 50%;
			transform: translate(-50%, -50%);
			z-index: 100;
			width: 540rpx;

			// height: 424rpx;
			.back-content-info {
				border-radius: 25rpx;
				width: 540rpx;
				height: 526rpx;
				padding: 50rpx 0 30rpx;

				.text {
					font-size: 150rpx;
				}
			}
		}
	}

	.container {
		height: 80vh;
	}

	.pop-btn {
		position: fixed;
		width: 100%;
		bottom: 100rpx;
		padding: 20rpx;
		background: #fff;
		margin-top: 0;
	}

	.pop-content {
		height: 142%;
		padding: 20rpx;
		padding-bottom: 120rpx;
	}

	.active2 {
		background: rgba($theme, 0.1);
		border: 1px solid $theme;
		color: $theme;
	}

	.box-item:nth-child(3n) {
		margin-right: 0;
	}

	.action-box {
		display: flex;
		margin-top: 30rpx;

		.action {
			flex: 1;
			height: 72rpx;
			line-height: 72rpx;
			border-radius: 62rpx 0px 0px 62rpx;
			;
			font-size: 24rpx;
			text-align: center;
		}

		.action+.action {
			margin-left: 4rpx;
			border-radius: 0px 62px 62px 0px;
		}

		.reset {
			color: $theme;
			background: rgba($theme, 0.3);
		}

		.confirm {
			color: #FFFFFF;
			background: $bgtheme1;
		}
	}

	.list-popup {
		background-color: #fff;
		width: 560rpx;
		border-radius: 16rpx;
		padding: 24rpx;
		min-height: 50rpx;

		.item {
			margin-bottom: 10rpx;
		}
	}
</style>